#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Create by zhang
# Create on 2022/7/27 7:41
from typing import List

from infrastructure.constant.response_constant import ResponseConstant
from infrastructure.rules.validators.validator_interface import ValidatorInterface, ValidatorModeEnum
from infrastructure.utils.result_wrap import ResponseWrapper


class MultiValidator(ValidatorInterface):
    def __init__(self, validators:List[ValidatorInterface]):
        assert validators is not None and len(validators) > 0
        super(MultiValidator, self).__init__()
        self.validators = validators

    def validate(self, value, mode:ValidatorModeEnum= ValidatorModeEnum.ALL) -> ResponseWrapper:
        for validator in self.validators:
            result = validator.validate(value, mode)
            if result.code == ResponseConstant.FAIL:
                return result
        return ResponseWrapper.success()